package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.MenuDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j
public class MenuServiceImpl implements MenuService {


    @Autowired
    private MenuDao menuDao;

    @Override
    //菜单分页查询
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        //调用dao, 获取检查项数据
        Page<Menu> page = menuDao.pageQuery(queryPageBean.getQueryString());
        //创建PageResult结果对象( 检查项的总记录数, 当前页显示需要的10条检查项数据 )
        return new PageResult(page.getTotal(), page.getResult());
    }

    //菜单添加
    @Override
    public void add(Menu menu) {
        menuDao.add(menu);
    }

    //点击编辑回显功能
    @Override
    public Menu findById(Integer id) {

        return menuDao.findById(id);
    }

    //编辑更改菜单
    @Override
    public void edit(Menu menu) {
        menuDao.edit(menu);
    }
    //删除菜单
    @Override
    public void delete(Integer id) {
        menuDao.delete(id);
    }
}
